﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;

namespace ChatServer.model
{
    public class User : dbconn.DBConnector
    {
        private string _username;
        private string _password;

        public string UserName
        {
            get { return _username; } //end get
            set { _username = value; }//end set
        }

        public string PassWord
        {
            get { return _password; } //end get
            set { _password = value; }//end set
        }

        //constructor is used for requiring username and password. verification on empty strings are implemented
        public User(string userName, string password)
        {
            
            //verify that the parameters are not empty
            if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
            {
                //if strings are not empty, pass values to private variables
                _username = userName;
                _password = password;
            }
            //do nothing if the variables are empty. when authenticating through serverSocket, variables will be found
            //empty and return false
        }

            
            // Calling this function to authenticate user_name and password from database then return a value true or false
            public Boolean Authentication(string _username, string _password)
            {
                List<SqlParameter> login = new List<SqlParameter>();
                SqlParameter user = new SqlParameter( "@username", _username);
                SqlParameter password = new SqlParameter("@password", _password);                
                login.Add(user);
                login.Add(password);
                DataTable dt = new DataTable();
                dt = SendDataTableRequest("ChatLogin", login);

                if (dt.Rows.Count > 0)
                
                    return true;
                 else
                    return false;
                              
            }
        }

}
